API-Test-Project
API Testing Project
This project demonstrates sample API applications in Java and Python, along with API testing frameworks using industry-standard tools.
Project Structure
Gemini-API-Test-Project/
|-- java-api/ # Contains the sample Java Spring Boot API application
| |-- src/
| | |-- main/
| | | `-- java/com/example/demo/
| | | |-- controller/HelloController.java
| | | `-- DemoApplication.java
| | `-- test/
| `-- pom.xml
|-- python-api/ # Contains the sample Python Flask API application
| |-- app.py
| `-- requirements.txt
|-- api-testing-frameworks/
| |-- java-rest-assured/ # API testing framework for Java and Python APIs using RestAssured
| | |-- src/
| | | `-- test/java/com/example/apitests/ApiTests.java
| | `-- pom.xml
| `-- python-pytest-requests/ # API testing framework for Java and Python APIs using Pytest and Requests
| |-- tests/test_api.py
| `-- requirements.txt
`-- README.md
How to Run the Applications
1. Java API (Spring Boot)
This API will run on http://localhost:8080.
- Navigate to the
java-apidirectory:bash cd Gemini-API-Test-Project/java-api - Build the application using Maven:
bash mvn clean install - Run the application:
bash mvn spring-boot:runThe API will be accessible athttp://localhost:8080/hello.
2. Python API (Flask)
This API will run on http://localhost:5000.
- Navigate to the
python-apidirectory:bash cd Gemini-API-Test-Project/python-api - (Optional) Create and activate a virtual environment:
bash python -m venv venv .\venv\Scripts\activate # On Windows # source venv/bin/activate # On macOS/Linux - Install the dependencies:
bash pip install -r requirements.txt - Run the application:
bash python app.pyThe API will be accessible athttp://localhost:5000/hello.
How to Run the API Tests
Before running the tests, ensure both the Java API and Python API applications are running.
1. Java API Tests (RestAssured)
- Navigate to the
java-rest-assureddirectory:bash cd Gemini-API-Test-Project/api-testing-frameworks/java-rest-assured - Run the tests using Maven:
bash mvn testThis will execute the tests defined inApiTests.java.
2. Python API Tests (Pytest with Requests)
- Navigate to the
python-pytest-requestsdirectory:bash cd Gemini-API-Test-Project/api-testing-frameworks/python-pytest-requests - (Optional) Create and activate a virtual environment (if not already done for the Python API):
bash python -m venv venv .\venv\Scripts\activate # On Windows # source venv/bin/activate # On macOS/Linux - Install the dependencies:
bash pip install -r requirements.txt - Run the tests using Pytest:
bash pytestThis will execute the tests defined intest_api.py.
A Note on Selenium WebDriver for API Testing
You initially mentioned using Selenium WebDriver for API testing. It's important to clarify that Selenium WebDriver is primarily designed for automating web browsers and testing user interfaces (UI). It simulates user interactions with a web page (like clicking buttons, filling forms, navigating pages).
API testing, on the other hand, involves directly interacting with the application's backend endpoints without a graphical user interface. This typically means sending HTTP requests (GET, POST, PUT, DELETE, etc.) and validating the responses.
While it's technically possible to use Selenium to interact with a web application that then makes API calls, it's an indirect and inefficient way to test the APIs themselves. It adds unnecessary overhead (browser startup, rendering) and doesn't allow for direct validation of API contracts, performance, or error handling at the API level.
For robust and efficient API testing, tools like RestAssured (for Java) and Requests with Pytest (for Python) are the industry standard. They allow for direct HTTP communication, easy assertion of response data, and are much faster and more reliable for this purpose than a UI automation tool like Selenium.